<?php
$item_name = strlen($dcommittee['Committee']['item_name'])>2 ? $dcommittee['Committee']['item_name'] : __('Project',true);
$dcommitteeName = $dcommittee['Committee']['short_name'];
if(isset($javascript)):
// load script in <head> section
$javascript->link('scriptaculous/lib/prototype', false);
$javascript->link('scriptaculous/src/scriptaculous', false);
$javascript->link('modalbox/modalbox', false);
echo $html->css('modalbox');
endif;
if(isset($javascript)):
?>
<script language="javascript" type="text/javascript">
<?php $options = '
            mode : "exact",     
            elements : "DecisionDesc'.$node.'",
            theme : "advanced",
            theme_advanced_buttons1 : "bold,italic,underline,|,undo,redo,|,cut,copy,paste,|,bullist,numlist,outdent,indent,|,sub,sup,",
            theme_advanced_buttons2 : "",
            theme_advanced_buttons3 : "",
            theme_advanced_toolbar_location : "top",
            theme_advanced_toolbar_align : "left",
            extended_valid_elements : "a[name|href|target|title|onclick],img[class|src|border=0|alt|title|hspace|vspace|width|height|align|onmouseover|onmouseout|name],hr[class|width|size|noshade],font[face|color|style],span[class|align|style]"';
?>
tinyMCE.init({<?php echo($options); ?>});
</script> 

<?php
endif;
?>
<script language="javascript" type="text/javascript">
/* standard small functions */
function $m(quem){
 return document.getElementById(quem)
}
function remove(quem){
 quem.parentNode.removeChild(quem);
}
function addEvent(obj, evType, fn){
 // elcio.com.br/crossbrowser
    if (obj.addEventListener)
        obj.addEventListener(evType, fn, true)
    if (obj.attachEvent)
        obj.attachEvent("on"+evType, fn)
}
function removeEvent( obj, type, fn ) {
  if ( obj.detachEvent ) {
    obj.detachEvent( 'on'+type, fn );
  } else {
    obj.removeEventListener( type, fn, false ); }
} 


function micoxUpload(form,url_action,id_element,html_show_loading,html_error_http){
 //testing if 'form' is a html object or a id string
 form = typeof(form)=="string"?$m(form):form;

 var erro="";
 if(form==null || typeof(form)=="undefined"){ erro += "The form of 1st parameter does not exists.\n";}
 else if(form.nodeName.toLowerCase()!="form"){ erro += "The form of 1st parameter its not a form.\n";}
 if($m(id_element)==null){ erro += "The element of 3rd parameter does not exists.\n";}
 if(erro.length>0) {
  alert("Error in call micoxUpload:\n" + erro);
  return;
 }

 //creating the iframe
 var iframe = document.createElement("iframe");
 iframe.setAttribute("id","micox-temp");
 iframe.setAttribute("name","micox-temp");
 iframe.setAttribute("width","0");
 iframe.setAttribute("height","0");
 iframe.setAttribute("border","0");
 iframe.setAttribute("style","width: 0; height: 0; border: none;");
 
 //add to document
 form.parentNode.appendChild(iframe);
 window.frames['micox-temp'].name="micox-temp"; //ie
 
 //add event
 var carregou = function() { 
   removeEvent( $m('micox-temp'),"load", carregou);
   var cross = "javascript: ";
   cross += "window.parent.$m('" + id_element + "').innerHTML = document.body.innerHTML; void(0); ";
   
   $m(id_element).innerHTML = html_error_http;
   $m('micox-temp').src = cross;
   //del the iframe
   setTimeout(function(){ remove($m('micox-temp'))}, 250);
  }
 addEvent( $m('micox-temp'),"load", carregou)

 //properties of form
 form.setAttribute("target","micox-temp");
 form.setAttribute("action",url_action);
 form.setAttribute("method","post");
 form.setAttribute("enctype","multipart/form-data");
 form.setAttribute("encoding","multipart/form-data");
 //submit
 form.submit();
 
 //while loading
 if(html_show_loading.length > 0){
  $m(id_element).innerHTML = html_show_loading;
 }
 
}

function beforeSubmit(obj,node,dcommittee, action){
    //get the url
    var montage=window.location.href.split("/");
    simple=montage.length-5;
    path="";
    for(var i=0;i<=simple;i++){
        path=path+montage[i]+"/";
    }
    var path = path + dcommittee + '/decisions/'+ action;
    tinyMCE.triggerSave();
    micoxUpload(obj,path,'upload_'+node,'Loading...','Error in upload');
    //Effect.Fade('formbox_'+node);
    Effect.Fade('minute_form'+node);
    Element.hide('close_button_'+node);
    Element.show('links_'+node);
    Element.show('processing_'+node);
    var dir = window.location;
    setTimeout("goD('"+dir+"','"+node+"')",6000);
}

function goD (path,node) {
    window.location = path;
}

function filedel(id, dcommittee){
	var new_id = "att"+id;
	var new_id2 = "att2"+id;
	
	document.getElementById(new_id).style.display = "none";
	document.getElementById(new_id2).style.display = "none";
	
	var montage=window.location.href.split("/");
    simple=montage.length-5;
    path="";
    for(var i=0;i<=simple;i++){
        path=path+montage[i]+"/";
    }
    var path = path + dcommittee + '/decisions/deletefile/'+id;
    ajaxFunction(path);
}
function ajaxFunction(path){
	var xmlhttp;
	if (window.XMLHttpRequest){
	  xmlhttp=new XMLHttpRequest();
	} else {
	  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
	if(xmlhttp.readyState==4){
	  document.myForm.time.value=xmlhttp.responseText;
	  }
	}
	xmlhttp.open("GET",path,true);
	xmlhttp.send(null);
}

</script>

<div id="processing_<?php echo $node;?>" style="display:none" >
    <br><strong>Data Processing...</strong>
</div>
<div class="minute_form" id="minute_form<?php echo $node;?>">
    
    <?php echo $this->element('minutes/decision_links',array('node'=>$node,'meetingid'=>$meetingid,'id'=>$id));?>
    <div id="close_button_<?php echo $node;?>" class="button close"  style='display:none;cursor:pointer;' onclick="Element.hide('close_button_<?php echo $node;?>');Effect.Fade('formbox_<?php echo $node;?>');Element.show('links_<?php echo $node;?>');">
        <?php __('X')?>
    </div>
    <div id="formbox_<?php echo $node;?>" class='formbox' style='display:none'>
        <div id="dec_form_<?php echo $node;?>" class='form'>
            <h2><?php __('New item')?></h2>
            <div>
                <form name="regform">
                    <?php
                        echo $form->hidden('meeting_id',array('value'=>$meetingid));
                        echo $form->hidden('node',array('value'=>$node));
                        echo $form->hidden('parent_id',array('value'=>$id));
						echo $form->hidden('item_name',array('value'=>$item_name));
                        echo $form->input(ucwords($item_name), array('options' => $items));
                        echo $form->input('description',array('class'=>'info','type'=>'textarea','cols'=>'14','rows'=>'5','id'=>'DecisionDesc'.$node)); 
                        echo $multiFile->input('additionalfiles'.$node,array('label'=>'Additional Files'));
                        echo $datePicker->picker('deadline',array('dateFormat'=>'Y-m-d','label'=>__('Decision deadline',true)));
                        echo $datePicker->picker('status_deadline',array('label'=>__('Update status deadline',true))); 
                        echo '<div class="fieldset-inside">';
                        echo $this->element('decisionusergrouplist',array('users'=>$users,'groups'=>$groups));
                        echo '</div>'
                    ?>
                    <button style="
                            background:#C0C0C0 none repeat scroll 0 0;
                            border:1px solid #808080;
                            color:#204B85;
                            display:inline;
                            font-size:100%;
                            font-weight:bold;
                            margin:10px 0 0;
                            padding:2px 5px;
                            vertical-align:bottom;
                            width:auto;"    
                        onClick="beforeSubmit(this.form,'<?php echo $node; ?>','<?php echo $dcommitteeName; ?>','addDecision')" 
                        type="button"><?php __('Save') ?></button>
                </form>
            </div>
        </div>
        <div id="upload_<?php echo $node;?>" class="recebe">&nbsp;</div>
        <div class="implementorlist" id="impl_list_<?php echo $node;?>" style="display:none;"></div>
    </div>
</div>

